var app = getApp();
var indexNumber = "";
Page({
  data: {
    authbg: getApp().globalData.source + "red_packet/bg.png",
    authtitle: getApp().globalData.source + "red_packet/title1.png",
    authbtn2: getApp().globalData.source + "red_packet/btn2.png",
    authdialog: getApp().globalData.source + "dialog/dialog.png",
    navList: [{
        "text": "日榜"
      },
      {
        "text": "周榜"
      },
      {
        "text": "月榜"
      }
    ],
    indexNumber: 0,
  },
  bindGetUserInfo: function(e) {
    getApp().authInfo(e);
  },
  clickItem: function(e) {
    var that = this;
    indexNumber = e.currentTarget.dataset.number;
    that.setData({
      indexNumber: indexNumber
    })
    if (indexNumber == 0) {
      var data = {
        "type": "day"
      }; //默认查询日排行
      that.findIncome(data);
    } else if (indexNumber == 1) {
      var data = {
        "type": "week"
      }; //默认查询日排行
      that.findIncome(data);
    } else if (indexNumber == 2) {
      var data = {
        "type": "month"
      }; //默认查询日排行
      that.findIncome(data);
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    //加载首页banner数据
    var data = {
      "type": "day"
    }; //默认查询日排行
    that.findIncome(data);
  },

  findIncome: function(data) {
    var that = this;
    app.requestLoading(app.globalData.https + "distributionActivity/distribution/findIncomeRanking",
      "get", data, "加载中...",
      function(res) {
        var data = res[0];
        if (data.code == "0") {
          var rankingLists = new Array();
          // 获取系统信息   
          var list = data.list;
          if (list.length > 0) {
            console.log(list)
            
            for (var i = 0; i < list.length; i++) {
              var numb = parseInt(1) + parseInt(i);
              rankingLists.push({
                "wxNickname": list[i].wxNickname,
                "imgUrl": "../../images/income/" + numb + ".png",
                "wxAvatarUrl": list[i].wxAvatarUrl,
                "sumBrokerage": list[i].sumBrokerage
              })
              if (i >= 2) {
                var rankingList = new Array();
                rankingList.push(rankingLists[1])
                rankingList.push(rankingLists[0])
                rankingList.push(rankingLists[2])
                that.setData({
                  rankingList: rankingList
                })
                break;
              }
            }
            if (list.length > 3) {
              list.splice(0, 3);
            }
            that.setData({
              dataList: list
            })
          } else {
            var userInfo = wx.getStorageSync("userInfo");
            rankingList = [{
              "imgUrl": userInfo.avatarUrl,
              "nickname": userInfo.nickName,
              "acount": 0.00
            }]
          }
        }
      },
      function(res) {
        console.log(res)
      }
    )
  },
})